
val studentToUpdateId = 1
val updatedMajor = "Data Science"
val studentsDF = spark.read.format("jdbc").option("url", "jdbc:mysql://localhost:3306/sparksql_practice").option("dbtable", "students").option("user", "root").option("password", "root").option("driver", "com.mysql.jdbc.Driver").option("useSSL", "false").load()
val updatedDF = studentsDF.withColumn(
  "major",
  when($"student_id" === studentToUpdateId, updatedMajor).otherwise($"major")
)
updatedDF.write
.format("jdbc")
.option("url", "jdbc:mysql://localhost:3306/sparksql_practice")
.option("dbtable", "students")
.option("user", "root")
.option("password", "root")
.option("driver", "com.mysql.jdbc.Driver")
.option("useSSL", "false")
.mode("overwrite")
.save()

val studentsDF = spark.read.format("jdbc").option("url", "jdbc:mysql://localhost:3306/sparksql_practice").option("dbtable", "students").option("user", "root").option("password", "root").option("driver", "com.mysql.jdbc.Driver").option("useSSL", "false").load()
val incrementedAgeDF = studentsDF.withColumn("age", $"age" + 1)
incrementedAgeDF.write
.format("jdbc")
.option("url", "jdbc:mysql://localhost:3306/sparksql_practice")
.option("dbtable", "students")
.option("user", "root")
.option("password", "root")
.option("driver", "com.mysql.jdbc.Driver")
.option("useSSL", "false")
.mode("overwrite")
.save()